package cn.liziguo.tank.script;

import cn.liziguo.tank.constants.ImageConst;
import com.almasb.fxgl.dsl.FXGL;
import com.almasb.fxgl.entity.component.Component;
import com.almasb.fxgl.entity.components.ViewComponent;
import javafx.scene.image.ImageView;

/**
 * @author Liziguo
 * @date 2022/7/16 15:11
 */
public class HomeComponent extends Component {

    private ViewComponent viewComponent;

    @Override
    public void onAdded() {
        entity.setUpdateEnabled(false);
    }


    public void destroy() {
        if (entity.getComponentOptional(GameOverComponent.class).isPresent()) {
            return;
        }
        // 设置为空就不会再碰撞了
        entity.setType(null);

        viewComponent.clearChildren();
        viewComponent.addChild(new ImageView(FXGL.image(ImageConst.HOME_FILED)));

        entity.setUpdateEnabled(true);
        entity.addComponent(new GameOverComponent());
    }
}
